/**
 * Company
 * Copyright (C) 2004-2018 All Rights Reserved.
 */
package com.idefav.crossdomaintest.controllers;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.ServletResponse;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;

/**
 * @author wuzishu
 * @version $Id HelloController.java, v 0.1 2018-03-15 下午9:00 wuzishu Exp $$
 */
@Controller
@RequestMapping("/hello")
public class HelloController {


    @RequestMapping(value = "/index",method = RequestMethod.GET)
    public String index(@RequestParam(name = "u") String userName, @RequestParam(name = "p") String pwd, Model model, HttpServletResponse response){
        model.addAttribute("userName", userName);
        model.addAttribute("password", pwd);
        Cookie cookie=new Cookie("userName",userName);
        cookie.setDomain("ceair.com");
        response.addCookie(cookie);

        Cookie cookie1=new Cookie("userName",userName);
        cookie1.setDomain("ce-air.com");
        response.addCookie(cookie1);
        return "index";
    }

    @RequestMapping(value = "/username",method = RequestMethod.GET)
    public String getCookie(){
        return "username";
    }

    @RequestMapping(value = "/setcookie")
    public String setCookie(@RequestParam(name = "u") String userName,HttpServletResponse response){
        Cookie cookie1=new Cookie("userName",userName);
        cookie1.setDomain("ce-air.com");
        response.addCookie(cookie1);

        response.addHeader("P3P", "CP='IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT'");
        return "setcookie";
    }


}
